/*

 */
package com.ohos.connent.bizscenecloud.biz.modular.device.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.bizscenecloud.biz.modular.device.entity.BusinessDevLibFile;
import com.ohos.connent.bizscenecloud.biz.modular.device.param.*;
import com.ohos.connent.bizscenecloud.biz.modular.device.result.BizDeviceUploadAuthResult;
import com.ohos.connent.bizscenecloud.biz.modular.device.service.BizDeviceService;
import com.ohos.connent.bizscenecloud.common.annotation.CommonLog;
import com.ohos.connent.bizscenecloud.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 设备管理库服务控制器
 **/
@Api(tags = "设备库文件管理控制器")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 1)
@RestController
@RequestMapping(value = "/api/v1/business/biz/device/devlib-file-manager")
@Validated
public class BizDeviceController {

    @Resource
    private BizDeviceService bizDeviceService;

    /**
     * 获取设备库文件管理分页数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取设备库文件管理分页数据")
    @PostMapping("/page")
    public CommonResult<Page<BusinessDevLibFile>> page(@RequestBody BizDevicePageParam bizDevicePageParam) {
        return CommonResult.data(bizDeviceService.page(bizDevicePageParam));
    }

    /**
     * 返回文件上传授权URL和文件id
     *
     *
     **/
    @ApiOperationSupport(order = 2)
    @ApiOperation("获取华为云文件上传授权URL和文件id")
    @CommonLog("获取华为云文件上传授权URL和文件id")
    @PostMapping("/file/getHWYunUploadAuthUrlAndFileId")
    public CommonResult<BizDeviceUploadAuthResult> getHWYunUploadAuthUrlAndFileId(@RequestBody BizDeviceUploadParam bizDeviceUploadParam) {
        return CommonResult.data(bizDeviceService.getHWYunUploadAuthUrlAndFileId(bizDeviceUploadParam));
    }

    /**
     * 新增设备库文件
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("新增设备库文件")
    @CommonLog("新增设备库文件")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizDeviceAddParam bizDeviceAddParam) {
        bizDeviceService.add(bizDeviceAddParam);
        return CommonResult.ok();
    }

    /**
     * 删除设备库文件：逻辑删除
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除设备库文件")
    @CommonLog("删除设备库文件")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid BizDeviceIdsParam bizDeviceIdsParam) {
        bizDeviceService.delete(bizDeviceIdsParam);
        return CommonResult.ok();
    }


    /**
     * 获取华为云文件下载授权URL
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取华为云文件下载授权URL")
    @CommonLog("获取华为云文件下载授权URL")
    @PostMapping("/file/getFileDownloadAuthUrlHUAWEI")
    public CommonResult<String> getFileDownloadAuthUrlHUAWEI(@RequestBody @Valid BizDeviceIdParam bizDeviceIdParam) {
       return CommonResult.data(bizDeviceService.getFileDownloadAuthUrlHUAWEI(bizDeviceIdParam));
    }

    /**
     * 上传设备库文件
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("上传设备库文件")
    @CommonLog("上传设备库文件")
    @PostMapping("/file/upload")
    public CommonResult<String> upload(@RequestPart("file") MultipartFile file,
                                       @RequestParam @NotEmpty(message = "文件id不能为空") String fileId) {
        bizDeviceService.upload(file, fileId);
        return CommonResult.ok();
    }

}
